//
//  WYTSameCityClassVC.m
//  WuyouTang
//
//  Created by yunbao02 on 2024/8/29.
//  Copyright © 2024 cat. All rights reserved.
//

#import "WYTSameCityClassVC.h"

#import "HXSearchBar.h"
#import "videoTopicCell.h"

@interface WYTSameCityClassVC ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>{
    HXSearchBar *searchBars;
    NSMutableArray *allArray;
    int p;
}
@property (nonatomic,strong) UITableView *videoClassTableView;

@end

@implementation WYTSameCityClassVC

- (UIStatusBarStyle)preferredStatusBarStyle {
    if (_isBlakcUI) {
        return UIStatusBarStyleLightContent;
    }
    if (@available(iOS 13.0,*)) {
        return UIStatusBarStyleDarkContent;
    }
    return UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleL.text = YZMsg(@"同城分类");
    if (!_isBlakcUI) {
        self.subNavi.backgroundColor = UIColor.whiteColor;
        self.titleL.textColor = UIColor.blackColor;
        self.naviLine.hidden = NO;
        self.naviLine.backgroundColor = RGB(250, 250, 250);
        [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
        self.view.backgroundColor = RGB_COLOR(@"#f5f5f5", 1);
    }else {
        self.view.backgroundColor = RGB_COLOR(@"#110D24", 1);//Normal_Color;
    }
    self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
    allArray = [NSMutableArray array];
    p = 1;
    
    [self.view addSubview:self.videoClassTableView];
    [self requestData];
    
}
- (void)requestData{
    [WYNetworking postWithUrl:@"Home.getCityClassLists" Dic:nil Suc:^(int code, id info, NSString *msg) {
        [_videoClassTableView.mj_header endRefreshing];
        [_videoClassTableView.mj_footer endRefreshing];
        if (code == 0) {
            [allArray removeAllObjects];
            NSArray *infoA = [NSArray arrayWithArray:info];
            [allArray addObjectsFromArray:infoA];
            [_videoClassTableView reloadData];
        }else {
            [MBProgressHUD showPop:msg];
        }
        
    } Fail:^(id fail) {
        [_videoClassTableView.mj_header endRefreshing];
        [_videoClassTableView.mj_footer endRefreshing];
    }];
}
- (UITableView *)videoClassTableView{
    if (!_videoClassTableView) {
        _videoClassTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, statusbarHeight+64, _window_width, _window_height-64-statusbarHeight)];
        _videoClassTableView.backgroundColor = UIColor.clearColor;
        _videoClassTableView.delegate = self;
        _videoClassTableView.dataSource = self;
        _videoClassTableView.separatorStyle = 0;
        [self.view addSubview:_videoClassTableView];
    }
    return _videoClassTableView;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 44)];
    if (!_isBlakcUI) {
        view.backgroundColor = RGB_COLOR(@"#f5f5f5", 1);
    }
    UILabel *label = [[UILabel alloc]init];
    label.font = [UIFont systemFontOfSize:14];
    if (!_isBlakcUI) {
        label.textColor = RGB_COLOR(@"#333333", 1);
    }else {
        label.textColor = RGB_COLOR(@"#959595", 1);
    }
    label.text = YZMsg(@"所有分类");
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left).offset(15);
        make.centerY.equalTo(view);
    }];
    
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return allArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    videoTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"videoTopicCELL"];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"videoTopicCell" owner:nil options:nil] lastObject];
    }
    cell.imgView.hidden = YES;
    [cell.topicTitleL mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cell.contentView).offset(15);
        make.centerY.equalTo(cell.contentView);
    }];
    cell.topicTitleL.text = minstr([allArray[indexPath.row] valueForKey:@"title"]);
    if (!_isBlakcUI) {
        cell.topicTitleL.textColor = RGB_COLOR(@"#333333", 1);
        cell.backgroundColor = UIColor.whiteColor;
        cell.contentView.backgroundColor = UIColor.whiteColor;
        cell.lineView.backgroundColor = RGB_COLOR(@"#ebebeb", 1);
    }else {
        cell.backgroundColor = CellRow_Cor;
        cell.contentView.backgroundColor = CellRow_Cor;
    }
    return cell;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 52;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.sameCityClassEvent) {
        self.sameCityClassEvent(allArray[indexPath.row]);
        [self.view endEditing:YES];
        if (!_isBlakcUI) {
            [[YBBaseAppDelegate sharedAppDelegate] popViewController:YES];
        }else {
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    }
}


@end
